﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AntiObesity.Base;
using AntiObesity.Base.Managers;

namespace AntiObesity.Services
{
    public partial class Signup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        protected void btnSignup_Click(object sender, EventArgs e)
        {
            // TODO: server side validation

            var user = new User
            {
                Name = txtUserName.Text,
                Password = txtPassword.Text,
                Sex = Convert.ToBoolean(rduSex.SelectedValue),
                DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text)
            };
            UserManager.Persist(user);
            BodyHistoryManager.PersistHistory(
                user.ID,
                (float)Convert.ToDouble(txtWeight.Text),
                (float)Convert.ToDouble(txtHeight.Text));
            Session.SetCurrentUser(user);
            Response.Redirect("UserHome.aspx");
        }
    }
}
